package ch.gislb2;

import ch.gislb2.intents.AngleofViewIntent;
import ch.gislb2.intents.ArmlengthIntent;
import ch.gislb2.intents.CalculationExecutedIntent;
import ch.gislb2.intents.ExecuteCalculationIntent;
import ch.gislb2.intents.ParallaXisBaseIntent;
import ch.gislb2.interf.ParallaXisObservable;
import ch.gislb2.interf.ParallaXisObserver;

public class ParallaPresenter implements ParallaXisObserver{

	private ParallaView view;
	private ParallaModel model;
	
	public ParallaPresenter(ParallaView view, ParallaModel model)
	{
		if(view != null)
			this.view = view;
		else
			throw new IllegalArgumentException("View is Null.");
		
		if(model != null)
			this.model = model;
		else
			throw new IllegalArgumentException("Model is Null.");
	}

	public void update(ParallaXisObservable observer, ParallaXisBaseIntent data) {
		if(data != null && data instanceof ParallaXisBaseIntent)
		{
			if(data instanceof AngleofViewIntent)
			{
				model.setIntent(data);
			}
			else if(data instanceof ArmlengthIntent)
			{
				model.setIntent(data);
			}
			else if(data instanceof ExecuteCalculationIntent)
			{
				model.setIntent(data);
				
			}
			else if(data instanceof CalculationExecutedIntent)
			{
				view.setIntent(data);
			}
			else
			{
				throw new IllegalArgumentException("Unsupported Intent."); 
			}
		}
		else
			throw new IllegalArgumentException("Illegal Intent.");
		
	}

}
